package com.eeds.controller.pc;

import com.eeds.base.BaseController;
import com.eeds.common.enums.TemplateEnum;
import com.eeds.common.model.BaseWrapper;
import com.eeds.common.table.UserBaseInfoEntity;
import com.eeds.common.table.UserRoleEntity;
import com.eeds.interceptor.NeedAuth;
import com.eeds.json.GsonUtil;
import com.eeds.model.role.req.ReqGetRoleInfoListVO;
import com.eeds.model.word.req.ReqExportDocVO;
import com.eeds.service.word.WordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.io.*;

@RestController
@Api(value = "word接口", description = "word接口")
@RequestMapping("pc/word/")
@Slf4j
public class WordController extends BaseController {


    @Autowired
    private WordService wordService;


    @RequestMapping(value = "/exportDoc", method = RequestMethod.GET)
    @ApiOperation("导出word")
    public void exportDoc(@Valid @ModelAttribute ReqExportDocVO reqExportDocVO){
        OutputStream outputStream = null;
        try {
            response.setContentType("application/msword");
            response.setHeader("Content-Disposition", "attachment;filename=" + System.currentTimeMillis() +".doc");
            String path = wordService.exportDoc(reqExportDocVO);
            wordService.exportDoc(path,response.getOutputStream());
            outputStream.flush();
        }catch (Exception e) {

        }finally {
            try {
                if(outputStream != null) {
                    outputStream.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }


}
